
import { _decorator, Component, Node, AudioClip, AudioSource, Sprite, Color, BoxCollider2D, Prefab, TiledMap, find } from 'cc';
import { eventTarget } from '../Globle';
const { ccclass,property } = _decorator;
 
@ccclass('AttackedWall')
export class AttackedWall extends Component {
    private audioSource:AudioSource;
    onLoad () {
        
        this.audioSource = this.getComponent(AudioSource);
        this.audioSource.node.on(AudioSource.EventType.ENDED,this.soundEnd,this);
        eventTarget.on('destoryAttackedWall',this.onAttacked,this);
    }

    //被攻击
    private onAttacked(uuid:string) {
        if(uuid==this.node.uuid){
            this.audioSource.play();
            this.getComponent(Sprite).color = new Color(0,0,0,0);
            this.node.getComponent(BoxCollider2D).destroy();
        }
    }

    private soundEnd() {
        this.node.destroy();
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
